<!DOCTYPE html >
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" th:href="@{bootstrap/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{css/main.css}">
    <style>
        .tree li {
            list-style-type: none;
            cursor: pointer;
        }
        .tree-closed {
            height: 40px;
        }
        .tree-expanded {
            height: auto;
        }
    </style>
</head>

<body>
<div th:replace="../templates/nav"></div><br/>
<div class="container-fluid">
    <div class="row">
        <div th:replace="../templates/menu"></div>
        <div class="col-sm-6 col-sm-offset-4 col-md-6 col-md-offset-4 main">

        <div class="form-group">
            <input type="hidden" id="aid" th:value="${aid}">
            <input type="hidden" id="apalce3" th:value="${apalce}">
            <input type="hidden" id="begin3" th:value="${begin}">
            <input type="hidden" id="end3" th:value="${end}">

            <label for="apalce" style="float:left;">活动主题：</label><input  id="apalce" class="form-control ">
            <label for="atime" style="float:left;">活动时间：</label><input id="atime" class="form-control " >
            <label for="uname" style="float:left;">发起人：</label><input  id="uname" class="form-control ">
        </div>

        <div class="form-group">
            <label for="descrition" style="float:left;">活动描述：</label><input  id="descrition" class="form-control ">
        </div>

            <label for="good" style="float:left;">支持：</label><div id="good" style="float: left;"></div><div style="float: left;">人</div>

        <div class="form-group" id="goods">
<!--            <div id="good2" style="float: right;width: 40px" onclick="goodDo()">点赞</div><br/>-->
        </div>
        <!--                       已有 评论-->
            <label for="discuss" >评论区：</label><div class="form-group" id="discuss">
        </div>

        <!--                    新增 评论-->
        <div class="form-group" >
            <label for="atime">添加评论：</label><input id="discus" class="form-control " style="float:left;" ><div ><font color="red" id="assign"></font></div>
        </div>

        </div>
    </div>

    <div class="modal-footer">
        <button type="button" class="btn btn-default" onclick="retun()">返回</button>
        <button type="button" class="btn btn-primary" onclick="submit1()">提交评论 </button>
    </div>


    </div>
</div>
<script th:src="@{jquery/jquery-2.1.1.min.js}"></script>
<script th:src="@{|/jquery/jquery.md5.js|}"></script>
<script th:src="@{bootstrap/js/bootstrap.min.js}"></script>
<script th:src="@{script/docs.min.js}"></script>
<script type="text/javascript">
    $(function () {
        $(".list-group-item").click(function () {
            if ($(this).find("ul")) { // 3 li
                $(this).toggleClass("tree-closed");
                if ($(this).hasClass("tree-closed")) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });

        var aid = $("#aid").val()
        //判断是否点过赞
        isgood(aid)
    });

    function isgood(aid){
        url="/isgoodDo"
        $.get(url,"aid="+aid,function (data) {
            if (data.result == "已点赞") {
                $("#goods").html( '<div id="good3" style="float: right;width: 40px" onclick="badDo()">取消</div><br/>');
                //页面数据数据展示
                info(data.aid);
            }else if(data.result == "未点赞") {
                $("#goods").html( '<div id="good2" style="float: right;width: 40px" onclick="goodDo()">点赞</div><br/>');
                //页面数据数据展示
                info(data.aid);
            }
        })
    }

    function info(aid){
        url="/showDo"
        $.get(url,"aid="+aid,function (data){
            if(data.result){
                //点赞和点赞人
                var htmldata2 = "";
                $.each(data.discussList,function(index,discuss){
                    if(index == 0){
                        $("#aid").val(discuss.action.aid)
                        $("#apalce").val(discuss.action.apalce)
                        $("#atime").val(discuss.action.atime)
                        $("#uname").val(discuss.action.user.uname)
                        $("#descrition").val(discuss.action.descrition)
                        $("#good").text(discuss.action.good)
                    }
                    if(discuss.dname != null) {
                        htmldata2 = htmldata2 + " <label for='discus'><a>" + discuss.dname + "</a></label><a>:" + discuss.discus + "</a><br/>";
                    }
                })
                $("#discuss").html(htmldata2);
            }
        })
    }
    // 点赞
    function goodDo(){
        var aid = $("#aid").val();
        var good = $("#good").text();
        url="/goodDo";
        $.get(url,"aid="+aid+"&good="+good,function (data){
            if(data.result){
                $("#goods").html( '<div id="good3" style="float: right;width: 40px" onclick="badDo()">取消</div><br/>');
                info(data.aid);
            }
        },"json");
    }
    // 取消点赞
    function badDo(){
        var aid = $("#aid").val();
        var good = $("#good").text();
        url="/badDo"
        $.get(url,"aid="+aid+"&good="+good,function (data){
            if(data.result){
                $("#goods").html( '<div id="good2" style="float: right;width: 40px" onclick="goodDo()">点赞</div><br/>');
                info(data.aid);
            }
        })
    }

    //自己评论
    function submit1(){
        var discus = $("#discus").val();
        var aid = $("#aid").val();
        url="/submitDo"
        if(discus == null || discus == ""){
            $("#assign").text("评论为空")
            return
        }
        $.get(url,"discus="+discus+"&aid="+aid,function (data){
            if(data.result){
                //将文本框内容清空
                $("#discus").val("")
                $("#assign").text("")
                info(data.aid);
            }
        })
    }
    //返回到首页
    function retun(){
        var begin = $("#begin3").val()
        var end = $("#end3").val()
        var apalce = $("#apalce3").val()
        window.location.href="/actioninfo2main?apalce="+apalce+"&begin="+begin+"&end="+end;
    }

</script>

</body>
</html>